package com.bkgy.controller.qualityDaily.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bkgy.controller.qualityDaily.entity.QualityTuo;
import com.bkgy.controller.qualityDaily.mapper.IQualityTuoMapper;
import com.bkgy.controller.qualityDaily.service.IQualityTuoService;
import com.bkgy.sys.common.entity.ResultData;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.stereotype.Service;

import java.io.FileInputStream;
import java.io.IOException;
import java.math.BigDecimal;

@Service
public class QualityTuoServiceImpl extends ServiceImpl<IQualityTuoMapper,QualityTuo> implements IQualityTuoService {
    @Override
    public ResultData<String> importTechParam() {
        FileInputStream in = null;
        try {
            in = new FileInputStream("D:\\workspace\\项目文档\\test.xlsx");
            XSSFWorkbook excel = new XSSFWorkbook(in);
            XSSFSheet sheet = excel.getSheetAt(0);
            int lastRowNum = sheet.getLastRowNum();

            for (int i = 1; i <= lastRowNum; i++) {
                XSSFRow row = sheet.getRow(i);
                double outMatWt = row.getCell(0).getNumericCellValue();
                String guihu = row.getCell(1).getStringCellValue();
                String createTime = row.getCell(2).getStringCellValue();

                QualityTuo param = new QualityTuo();
                param.setCreateTime(createTime);
                param.setGuihu(guihu);
                param.setOutMatWt(BigDecimal.valueOf(outMatWt));
                save(param);
            }
            excel.close();
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            try {
                in.close();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return ResultData.ResultDataSuccess("success");
    }
}
